const helps = require("./helps.js");
const inquirer = require("inquirer");
const download = require("download-git-repo");
const ora = require("ora");
const colors = require("colors");
function help() {
  helps.forEach((element) => {
    console.log(element);
  });
}

function downFile(project) {
  inquirer
    // @ts-ignore
    .prompt([
      {
        type: "list",
        name: `projectName`,
        message: "请选择下载内容？",
        choices: [
          { name: "element_plus 文档", value: "element-plus-doc" },
          { name: "vant_ui 文档", value: "vant-ui-vue-doc" },
          { name: "vant_weapp 文档", value: "vant-weapp-doc" },
          { name: "express 初始化项目", value: "express-init" },
        ],
      },
    ])
    .then((res) => {
      const spinner = ora().start();
      spinner.text = "代码正在下载……";
      download(
        `direct:https://gitee.com/jiejiegg/down_file.git#${res.projectName}`,
        project,
        { clone: true, checkout: res.projectName },
        (err) => {
          if (err) {
            console.log(err);
            spinner.fail("代码下载失败");
          } else {
            spinner.succeed("代码下载成功");
          }
        }
      );
    });
}

module.exports = {
  help,
  downFile,
};
